<template>
    <div class="app-container" ref="content">
        <div style="text-align: center;padding: 10px">每日任务《   {{ dailyTasksInfo.taskName }}》-详情信息</div>
        <el-row :gutter="10">
          <div  style="text-align: center">
            <el-button size="mini"  type="primary" @click="inspectionRecord">巡检记录</el-button>
          </div>
            <el-col :xs="24" :sm="24" :md="24" :lg="24" :xl="24">
                <el-form :model="dailyTasksInfo" ref="dailyTasksInfo" label-width="150px">
                    <el-col :xs="24" :sm="24" :md="24" :lg="24" :xl="24">
                        <el-col :xs="24" :sm="24" :md="12" :lg="12" :xl="8">
                            <el-form-item label="所属主体:" prop="enterpriseName">
                                {{ dailyTasksInfo.enterpriseName }}
                            </el-form-item>
                        </el-col>
                        <el-col :xs="24" :sm="24" :md="12" :lg="12" :xl="8">
                            <el-form-item label="任务名称:" prop="taskName">
                                {{ dailyTasksInfo.taskName }}
                            </el-form-item>
                        </el-col>
                        <el-col :xs="24" :sm="24" :md="12" :lg="12" :xl="8">
                            <el-form-item label="领取时间" prop="receiveTime">
                                {{ dailyTasksInfo.receiveTime  |dateFormat}}
                            </el-form-item>
                        </el-col>
                        <el-col :xs="24" :sm="24" :md="12" :lg="12" :xl="8">
                            <el-form-item label="领取状态" prop="receiveStatus">
                                {{ dailyTasksInfo.receiveStatus | receiveStatus}}
                            </el-form-item>
                        </el-col>
                        <el-col :xs="24" :sm="24" :md="12" :lg="12" :xl="24">
                            <el-form-item label="任务内容:" prop="content">
                                {{ dailyTasksInfo.content }}
                            </el-form-item>
                        </el-col>
                        <el-col :xs="24" :sm="24" :md="12" :lg="12" :xl="8">
                            <el-form-item label="执行人员:" prop="userName">
                                {{ dailyTasksInfo.userName }}
                            </el-form-item>
                        </el-col>
                        <el-col :xs="24" :sm="24" :md="24" :lg="24" :xl=24>
                            <el-form-item label="执行状态:" prop="executeStatus">
                                {{ dailyTasksInfo.executeStatus | infoStatus }}
                            </el-form-item>
                        </el-col>

                        <uc-table url="admin/spectionTaskSignInfo/getSpectionTaskSignPage" name="巡检签到" ref="signTable" pageable table-border :search-form="searchForm">
                            <template slot="searchForm">
                            </template>
                            <template slot="columns">
                                <el-table-column prop="enterpriseName" label="主体名称" align="left" :show-overflow-tooltip="true"></el-table-column>
                                <el-table-column prop="equipmentName" label="设备名称" align="left" :show-overflow-tooltip="true"></el-table-column>
                                <el-table-column prop="signUserName" label="签到人员" align="left" :show-overflow-tooltip="true"></el-table-column>
                                <el-table-column prop="signTime" label="签到时间" align="left" :show-overflow-tooltip="true">
                                    <template slot-scope="scope">
                                        {{scope.row.signTime | dateFormat}}
                                    </template>
                                </el-table-column>
                                <el-table-column prop="address" label="操作" width="220" align="left" class-name="small-padding fixed-width">
                                    <template slot-scope="scope">
                                        <!--编辑按钮-->
                                        <el-button size="mini" icon="el-icon-edit" type="primary" @click="handleEdit(scope.row)">编辑</el-button>
                                        <el-button size="mini" icon="el-icon-info" type="success" @click="handleInfo(scope.row)">详情</el-button>
                                        <el-button size="mini" type="danger" icon="el-icon-delete" :loading="deleteLoading" @click="handleDelete(scope.row)">删除</el-button>
                                    </template>
                                </el-table-column>
                            </template>
                        </uc-table>
                    </el-col>
                </el-form>
            </el-col>
        </el-row>
    </div>
</template>

<script>
import {getInDailyTasksVo} from "@/api/dailyTasks";
import UcTable from "@/components/UcTable/index.vue";
import {deleteInspectionTaskSign} from "@/api/inspectionTaskSign";
import {getInTaskList} from "@/api/taskinfo";
import {getEquipmentList} from "@/api/equipment";
export default {
    name: "info",
    components: {UcTable},
    data(){
        return{
            dailyTasksInfo:{},
            searchForm:{
                deleted:false,
                taskId:this.$route.query.ucId,
            },
            taskList:[],
            equipmentList:[],
            deleteLoading:false,

        }
    },
    created() {
        console.log(this.$route.query.ucId)
        this.$nextTick(() => {
            this.getInDailyTasksVo(this.$route.query.ucId)
        });
        this.getEquipmentList()
        this.getInTaskList()
    },
    methods:{
        getInDailyTasksVo(val){
            //获取企业信息数据
            let loadingInstance = this.$loading({
                target:this.$refs.content,
                text:'数据加载中'
            });
            getInDailyTasksVo({ucId:val}).then(res=>{
                console.log(res)

                this.dailyTasksInfo = res.data
                loadingInstance.close()
                this.$notify.success({
                    title: '成功',
                    message: "获取每日信息成功"
                })
            }).catch(error=>{
                console.log(error)
                loadingInstance.close()
                this.$notify.error({
                    title: '失败',
                    message: "获取每日任务信息失败"
                })
            })
        },
      inspectionRecord(){
        this.$router.push("/taskManage/inspectionRecord?ucId="+this.dailyTasksInfo.ucId)
      },
        handleSearch(){
            this.$refs.signTable.getTableData(1)
        },
        handleEdit(val){
            this.$router.push("/taskManage/signEdit/"+val.id)
        },
        handleInfo(val){
            this.$router.push("/taskManage/signInfo/"+val.id)
        },
        clearEnterprise(){
            //清除企业下拉框
            this.searchForm.enterpriseId = null
            this.handleSearch()
        },
        clearTask(){
            //清除任务下拉框
            this.searchForm.taskId = null
            this.handleSearch()
        },
        clearEquipment(){
            //清除设备下拉框
            this.searchForm.equipmentId = null
            this.handleSearch()
        },
        handleDelete(val){
            this.$confirm('您确定要执行删除这个巡检签到吗？', '提醒信息', {
                confirmButtonText: '确定',
                cancelButtonText: '取消',
                type: 'warning'
            }).then(() => {
                this.deleteLoading = true
                deleteInspectionTaskSign(val).then(res=>{
                    this.deleteLoading = false
                    this.$notify.success({
                        title: '成功',
                        message: "删除巡检签到信息成功"
                    })
                    this.handleSearch()
                }).catch(res=>{
                    this.deleteLoading = false
                    this.$notify.error({
                        title: '失败',
                        message: res.msg
                    })
                })
            }).catch(() => {
                this.$message({
                    type: 'info',
                    message: '已取消删除'
                });
            });
        },
        getInTaskList(){
            getInTaskList({deleted:false}).then(res=>{
                this.taskList = res.data
            }).catch(error=>{

            })
        },
        getEquipmentList(){
            getEquipmentList({deleted:false}).then(res=>{
                this.equipmentList = res.data
            }).catch(error=>{

            })
        },

    },
    filters:{
        infoStatus(val){
            let status = "";
            switch (val){
                case 0:
                    status = "已领取";
                    break;
                case 1:
                    status = "执行中";
                    break;
                case 2:
                    status = "已执行";
                    break;
                case 3:
                    status = "已完成 ";
                    break;
                case 4:
                    status = "已过期 ";
                    break;
                default:
                    break;
            }
            return status;
        }
    }

}
</script>
